package com.ypj.indusynergyems.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ypj.indusynergyems.dao.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {

    //分页+搜索用户列表，如果username不为null，要根据用户名分页查询并分页，如果为null就不加搜索条件
    @Select("<script> "+"select u.*,IFNULL(r.role_name,'前台用户') as role_name " +
            " from user u left join shoprole r on u.role_id = r.role_id  " +
            "<where> "+
            "<if test='username!=null'> u.username like concat('%',#{username},'%')</if> " +
            "</where> "
            +"</script> ")
    List<UserEntity> findUserList(String username);

    @Select("SELECT * FROM user WHERE user_id IN (#{userIds})")
    List<UserEntity> selectByIds(List<Integer> userIds);
}
